package com.sqlcheck.dto.response;

import com.sqlcheck.entity.ScanResult;
import com.sqlcheck.model.OptimizationSuggestion;
import com.sqlcheck.model.SqlStatement;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.Builder;

import java.time.LocalDateTime;
import java.util.List;

@Data
@Builder
@Schema(description = "统一分析响应")
public class UnifiedAnalysisResponse {

    @Schema(description = "分析是否成功", example = "true")
    private boolean success;

    @Schema(description = "错误信息，分析失败时返回")
    private String errorMessage;

    @Schema(description = "分析的SQL语句列表")
    private List<SqlStatement> sqlStatements;

    @Schema(description = "发现的兼容性问题列表")
    private List<ScanResult> issues;

    @Schema(description = "优化建议列表")
    private List<OptimizationSuggestion> optimizations;

    @Schema(description = "优化后的SQL，仅LLM分析时有效")
    private String optimizedSql;

    @Schema(description = "优化说明，仅LLM分析时有效")
    private String optimizationExplanation;

    @Schema(description = "分析统计信息")
    private AnalysisStatistics statistics;

    @Schema(description = "分析完成时间")
    private LocalDateTime analysisTime;

    @Schema(description = "分析耗时（毫秒）")
    private Long duration;

    @Data
    @Builder
    @Schema(description = "分析统计信息")
    public static class AnalysisStatistics {
        @Schema(description = "总问题数")
        private Integer totalIssues;

        @Schema(description = "高严重程度问题数")
        private Integer highSeverityCount;

        @Schema(description = "中等严重程度问题数")
        private Integer mediumSeverityCount;

        @Schema(description = "低严重程度问题数")
        private Integer lowSeverityCount;

        @Schema(description = "信息级别问题数")
        private Integer infoSeverityCount;

        @Schema(description = "优化建议数")
        private Integer optimizationCount;

        @Schema(description = "语法问题数")
        private Integer syntaxIssueCount;

        @Schema(description = "函数兼容性问题数")
        private Integer functionIssueCount;

        @Schema(description = "数据类型问题数")
        private Integer datatypeIssueCount;

        @Schema(description = "性能问题数")
        private Integer performanceIssueCount;

        @Schema(description = "兼容性问题数")
        private Integer compatibilityIssueCount;

        @Schema(description = "安全风险问题数")
        private Integer securityIssueCount;
    }
}